package cn.ainit.base.approve;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.hibernate.Query;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.ainit.base.approve.entity.SysApprove;
import cn.ainit.common.ReturnObject;

@Service("approveServiceImpl")
@Transactional
public class ApproveServiceImpl implements ApproveService {
	
	private ApproveDao approveDao;
	
	@Resource
	public void setApproveDao(ApproveDao approveDao) {
		this.approveDao = approveDao;
	}

	@Override
	public List<SysApprove> listApproves(String djId) throws Exception {
		return this.approveDao.listApproves(djId);
	}
	@Override
	public boolean updApprove(String sql) throws Exception {
		return this.approveDao.updApprove(sql);
	}
	@Override
	public SysApprove getOneApprove(String djId, Integer djLevel)
			throws Exception {
		return this.approveDao.getOneApprove(djId, djLevel);
	}
	@Override
	public String getApproveTable(String type) throws Exception {
		return this.approveDao.getApproveTable(type);
	}
	@Override
	public String getValue(String sql) throws Exception {
		return this.approveDao.getValue(sql);
	}
	
	@Override
	public String getDsName(String dsId) throws Exception{
		return approveDao.getDsName(dsId);
	}

	@Override
	public SysApprove getApproveByPks(String djId, String djLevel, String djType) throws Exception {
		return approveDao.getApproveByPks(djId, djLevel, djType);
	}

	@Override
	public Integer maxDjLevel(SysApprove sysApprove) throws Exception{
		return approveDao.maxDjLevel(sysApprove);
	}
	@Override
	public Integer minDjLevel(String djId) throws Exception {
		return approveDao.minDjLevel(djId);
	}

	
	@Override
	public Integer upAllApplyByDjId(String djId) throws Exception {
		return approveDao.upAllApplyByDjId(djId);
	}

	@Override
	public Integer upApplyByIdLevel(String djId, String djLevel)
			throws Exception {
		return approveDao.upApplyByIdLevel(djId, djLevel);
	}

	@Override
	public String getApprove(String djId, String djLevel, String djType)
			throws Exception {
		return approveDao.getApprove(djId, djLevel, djType);
	}

	@Override
	public String getPKByDjType(String djType) throws Exception {
		return approveDao.getPKByDjType(djType);
	}
	@Override
	public List<SysApprove> dataById(String id,String dsId) throws Exception {
		return this.approveDao.dataById(id,dsId);
	}
	@Override
	public String  getMaxApplyLevelByDsId(String dsId,String param1) throws Exception{
		return this.approveDao.getMaxApplyLevelByDsId(dsId, param1);
	}
	
	@Override
	public ReturnObject produceApproveList(String djId,String dsId,String djType,String djCode,HttpSession session) throws Exception{
		return this.approveDao.produceApproveList(djId, dsId, djType, djCode,session);
	}
	
	@Override
	public String getExamineManFkVal(Integer level,String dsId,String param) throws Exception{
		return this.approveDao.getExamineManFkVal(level, dsId, param);
	}
	
	@Override
	public List getItemsCodes (String sql) throws Exception{
		return this.approveDao.getItemsCodes(sql);
	}
	
	@Override
	public Boolean sureSaveAppr(SysApprove sysApprove,HttpSession session)
			throws Exception {
		boolean flag=true;
		try {
			flag=this.approveDao.sureSaveAppr(sysApprove,session);
		} catch (Exception e) {
			flag=false;
			e.printStackTrace();
			throw e;
		}
		return flag;
	}

	@Override
	public String checkApprovePass(Integer level,String dsId, String djId,String param)  throws Exception {
		return this.approveDao.checkApprovePass(level,dsId,djId,param);
	}

	@Override
	public boolean updateDjVerify(String table, String pkName,String pkVal,HttpSession session) throws Exception {
		return this.approveDao.updateDjVerify(table, pkName, pkVal,session);
		
	}

	@Override
	public boolean sureApproveShowMsg(String djId,Integer approveLevel,String dsId,HttpSession session) throws Exception {
		return this.approveDao.sureApproveShowMsg(djId, approveLevel, dsId, session);
	}

	@Override
	public SysApprove getMinLevelAppObj(String djId,String dsId) throws Exception {
		return this.approveDao.getMinLevelAppObj(djId,dsId);
	}

	@Override
	public ReturnObject  updateIsVerify(Integer approveLevel,String djId,String dsId,HttpSession session) throws Exception {
		return this.approveDao.updateIsVerify(approveLevel,djId,dsId,session);
	}

	@Override
	public String delApproveFlow(String regId, Integer curLevel, String flowId)
			throws Exception {
		return this.approveDao.delApproveFlow(regId, curLevel, flowId);
	}

	@Override
	public Integer getIsApproveRight(String soureId, String djId, String dsId,
			HttpSession session) throws Exception {
		return this.approveDao.getIsApproveRight(soureId, djId, dsId, session);
	}

	/***
	 * 最高一级的领导审批通过之后确认驳回
	 * @param session
	 * @return
	 * @author feifei
	 * @date: 2015-3-31 下午04:32:28 
	 */
	@Override
	public ReturnObject sureRejectByLead(String djId,String dsId,String code,HttpSession session) throws Exception{
		return this.approveDao.sureRejectByLead(djId, dsId, code, session);
	}

	/***
	 * 根据dsid判断单据是否有审批
	 * @param dsId
	 * @param param
	 * @return
	 * @throws Exception
	 * @author feifei
	 * @date: 2015-4-2 上午11:15:08 
	 */
	@Override
	public String isRejectByDsId(String dsId, String param) throws Exception {
		String flag=null;
		try {
			flag=this.approveDao.isRejectByDsId(dsId, param);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return flag;
	}

	@Override
	public String checkSubmitData(String djId, String dsId, String prams,
			HttpSession session) throws Exception {
		
		return this.approveDao.checkSubmitData(djId, dsId, prams, session);
	}

	@Override
	public String getMaster(String djId, String dsId, HttpSession session)
			throws Exception {
		return this.approveDao.getMaster(djId, dsId, session);
	}
	
	
	
	
}
